package com.coocaa.ops.admin.v1.audit.provider.impl;


import com.coocaa.ops.admin.base.AbstractBizImpl;
import com.coocaa.ops.admin.base.language.CommonLanguageProperties;
import com.coocaa.ops.admin.v1.audit.model.CheckInfoModel;
import com.coocaa.ops.admin.v1.audit.provider.AbstractAuditTaskProviderImpl;
import com.coocaa.ops.admin.v1.policygroup.biz.impl.PolicyGroupInfoBizImpl;
import com.coocaa.ops.admin.v1.policygroup.service.impl.PolicyGroupInfoQueryServiceImpl;
import com.coocaa.ops.common.core.base.model.ResourceBaseModel;
import com.coocaa.ops.common.core.base.util.ResourceStatusValidator;
import com.coocaa.ops.common.core.biz.homepage.entity.HomepageInfoEntity;
import com.coocaa.ops.common.core.biz.panel.entity.BlockContentConfigInfo;
import com.coocaa.ops.common.core.biz.policygroup.entity.PolicyGroupInfoEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

/**
 * @author bjh
 * @description 策略组信息原始表 审核-撤销审核-上架操作 提供者接口
 * @date : 2020-03-12 14:46:04
 */
@Service
public class PolicyGroupInfoAuditTaskProviderImpl extends AbstractAuditTaskProviderImpl<PolicyGroupInfoEntity> {
    @Autowired
    private PolicyGroupInfoBizImpl thisBizImpl;
    @Autowired
    private PolicyGroupInfoQueryServiceImpl policyGroupInfoQueryService;
    private static CommonLanguageProperties commonLanguageProperties;

    @Override
    public AbstractBizImpl getAbstractBizImpl() {
        return thisBizImpl;
    }

    @Override
    public CheckInfoModel checkBeforeAudit(ResourceBaseModel resourceBaseModel) {
        PolicyGroupInfoEntity entity = policyGroupInfoQueryService.getDetailInfo(resourceBaseModel.getId(), resourceBaseModel.getVersion());
        Assert.notNull(entity, commonLanguageProperties.getPolicyGroupInfo() + commonLanguageProperties.getNotNull());
        HomepageInfoEntity homepageInfoEntity = entity.getNormalHomepage();
        Assert.notNull(homepageInfoEntity, commonLanguageProperties.getHomepage() + " info " + commonLanguageProperties.getNotNull());
        if (ResourceStatusValidator.isNotOnline(homepageInfoEntity.getStatus())) {
            //存在没有审核通过的首页
            return CheckInfoModel.getCheckInfoModel(Boolean.TRUE, getCheckMsg(homepageInfoEntity));
        }
        return super.checkBeforeAudit(resourceBaseModel);
    }

    @Autowired
    public void setCommonLanguageProperties(CommonLanguageProperties commonLanguageProperties) {
        PolicyGroupInfoAuditTaskProviderImpl.commonLanguageProperties = commonLanguageProperties;
    }

    /**
     * 获取校验信息
     *
     * @param homepageInfoEntity
     * @return
     */
    private String getCheckMsg(HomepageInfoEntity homepageInfoEntity) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("homepageID: [")
                .append(homepageInfoEntity.getId())
                .append("],")
                .append("homepageName： ")
                .append(homepageInfoEntity.getHomepageName())
        ;
        return stringBuilder.toString();
    }

}
